﻿using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace FluentlyXml.Core
{
	internal class PropertySerializerDictionary : IEnumerable<KeyValuePair<string, PropertySerializer>>
	{
		private readonly IDictionary<string, PropertySerializer> _propertiesToSerializers = new Dictionary<string, PropertySerializer>();

		//TODO: Eventually, let's not use PropertyInfo here, let's use something else.  Probably not a string
		//		since that's not a strong enough concept...
		public PropertySerializer this[PropertyInfo property]
		{
			get { return _propertiesToSerializers[property.Name]; }
			set { _propertiesToSerializers[property.Name] = value; }
		}

		public void MergeWith(PropertySerializerDictionary propertySerializers)
		{
			foreach (var propertySerializer in propertySerializers._propertiesToSerializers)
			{
				_propertiesToSerializers[propertySerializer.Key] = propertySerializer.Value;
			}
		}

		public IEnumerator<KeyValuePair<string, PropertySerializer>> GetEnumerator()
		{
			return _propertiesToSerializers.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public void Add(string propertyName, PropertySerializer propertySerializer)
		{
			_propertiesToSerializers[propertyName] = propertySerializer;
		}
	}
}